/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rafkind.resrev.web.page;

import com.rafkind.resrev.data.Resource;
import com.rafkind.resrev.data.User;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

/**
 *
 * @author Fictional Hero
 */
public class ColorfulPropertyColumn extends PropertyColumn {

  private Stylist stylist;
  
  public ColorfulPropertyColumn(IModel<String> arg0, String arg1, Stylist stylist) {
    super(arg0, arg1);
    this.stylist = stylist;
  }

  public ColorfulPropertyColumn(IModel<String> arg0, String arg1, String arg2, Stylist stylist) {
    super(arg0, arg1, arg2);
    this.stylist = stylist;
  }
  private static SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy hh:mm aa");

  @Override
  public void populateItem(Item item, String componentId, IModel model) {
    
    PropertyModel m = new PropertyModel(model, getPropertyExpression());

    if (m.getObject() instanceof Date) {
      Label label = new Label(componentId, sdf.format(m.getObject()));
      label.add(createColorAttribute(model));
      item.add(label);
    } else {
      Label label = new Label(componentId, createLabelModel(model));
      label.add(createColorAttribute(model));
      item.add(label);
    }
  }

  private SimpleAttributeModifier createColorAttribute(IModel model) {    
    
    return new SimpleAttributeModifier(
        "style",
        stylist.getStyleFor(model.getObject()));
  }
}
